home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / FORM_DO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-14  |  14.8 KB  |  619 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <VDI.H>
  9. #include <OSBIND.H>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "XA_DEFS.H"
  15. #include "BOX3D.H"
  16. #include "FRM_ALRT.H"
  17. #include "K_DEFS.H"
  18. #include "RESOURCE.H"
  19. #include "OBJECTS.H"
  20. #include "WATCHBOX.H"
  21. #include "C_WINDOW.H"
  22. #include "STD_WIDG.H"
  23. #include "SCRLOBJC.H"
  24.  
  25. #if 0
  26. #define CLIP(tree,obj,x,y,w,h)                 \
  27.     object_abs_coords(tree, obj, &x, &y);    \
  28.     w = tree[obj].ob_width;                    \
  29.     h = tree[obj].ob_height;                \
  30.     set_clip(x, y, w, h);
  31. #endif
  32.  
  33. #define CLIP(tree,obj,x,y,w,h)    clear_clip()
  34. #define set_clip(x,y,w,h)        /* We don't want this now! */
  35.  
  36. #if 0
  37. #undef CLIP            /* Those set_clip(..) can't be useful */
  38. #endif
  39.  
  40. /* Returns the object number of this object's parent or -1 if it is the root*/
  41. short GetParent(OBJECT *t, short object)
  42. {
  43.     short last;
  44.     
  45.     if (object == 0)
  46.         return -1;
  47.     else {
  48.         do {
  49.             last = object;
  50.             object = t[object].ob_next;
  51.         } while(t[object].ob_tail != last);
  52.         return object;
  53.     }
  54. }
  55.  
  56. /*
  57.   Sets one of a group of radio buttons, and clears the rest.
  58.   Includes patch to allow for pop_icons as radio buttons.
  59. */
  60. void Radio_b(OBJECT *d, short object)
  61. {
  62.     short parent, o, x, y, w, h;
  63.  
  64.     if ((parent = GetParent(d, object)) == -1)
  65.         return;        /* Only reasonable thing to do */
  66.  
  67.     o = d[parent].ob_head;
  68.     
  69.     while (o != parent)
  70.     {
  71.         if ((d[o].ob_flags & RBUTTON) && (d[o].ob_state & SELECTED))
  72.         {
  73.             d[o].ob_state &= ~SELECTED;
  74.  
  75.             CLIP(d, o, x, y, w, h);
  76.             v_hide_c(V_handle);
  77.             draw_object_tree(d, o, MAX_DEPTH);
  78.             v_show_c(V_handle, 1);
  79.         }
  80.         
  81.         o = d[o].ob_next;
  82.     }
  83.     
  84.     d[object].ob_state |= SELECTED;
  85.  
  86.     CLIP(d, object, x, y, w, h);
  87.     v_hide_c(V_handle);
  88.     draw_object_tree(d, object, MAX_DEPTH);
  89.     v_show_c(V_handle, 1);
  90. }
  91.  
  92. /*
  93.     Form_do() click handler
  94. */
  95. short click_object_widget(XA_WINDOW *wind, XA_WIDGET *widg)
  96. {
  97.     short x, y, w, h, f, is, os;
  98.     unsigned long retv = XA_OK;
  99.     XA_WIDGET_TREE *wt = (XA_WIDGET_TREE*)widg->stuff;
  100.     OBJECT *form;
  101.     GRECT r;
  102.  
  103. #if 0
  104.     if (window_list != wind)    /* You can only work alerts when they are on top */
  105.         return FALSE;
  106. #endif
  107.     if (window_list != wind) {
  108.         v_hide_c(V_handle);
  109.         pull_wind_to_top(wind);
  110.         display_window(wind);
  111.         v_show_c(V_handle, 1);
  112.         return FALSE;
  113.     }
  114.    
  115.     form = wt->tree;
  116.  
  117.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  118.  
  119.     f = find_object(form, 0, 10, x + widg->click_x, y + widg->click_y);
  120.  
  121.     /* find_object can't report click on a HIDETREE object. */
  122. #if 0
  123.     if (((form[f].ob_flags & HIDETREE)        /* Was click on a valid selectable object? */
  124. #endif
  125.     if ((form[f].ob_state & DISABLED)    /* Was click on a valid selectable object? */
  126.         ||(!(form[f].ob_flags & (EDITABLE | SELECTABLE | EXIT | TOUCHEXIT))))
  127.     {    
  128.         return FALSE;
  129.     }
  130.  
  131.     if (form[f].ob_type==G_SLIST)
  132.     {
  133.     
  134.         click_scroll_list(form,f,x+widg->click_x,y+widg->click_y);
  135.     
  136.     }else{
  137.  
  138.         if ((form[f].ob_flags & EDITABLE) && (f != wt->edit_obj))    /* Select a new editable text field? */
  139.         {
  140.             TEDINFO *txt=(TEDINFO*)form[f].ob_spec;
  141.         
  142.             form[f].ob_state |= IS_EDIT;
  143.             form[wt->edit_obj].ob_state &= ~IS_EDIT;
  144.  
  145.             CLIP(form, wt->edit_obj, x, y, w, h);
  146.             v_hide_c(V_handle);
  147.             draw_object_tree(form, wt->edit_obj, MAX_DEPTH);
  148.  
  149.             wt->edit_obj = f;
  150.             wt->edit_pos = txt->te_tmplen = strlen(txt->te_ptext);
  151.         
  152.             CLIP(form, f, x, y, w, h);
  153.             draw_object_tree(form, f, MAX_DEPTH);
  154.             v_show_c(V_handle, 1);
  155.         }
  156.  
  157.         CLIP(form, f, x, y, w, h);
  158.  
  159.         os = form[f].ob_state;
  160.         is = os ^ SELECTED;
  161.  
  162.          if (form[f].ob_flags & TOUCHEXIT)    /* Touch Exit button? */
  163.         {
  164.             if (form[f].ob_flags & RBUTTON) {    /* Was click on a radio button? */
  165.                 Radio_b(form, f);
  166.             } else if (form[f].ob_flags & SELECTABLE) {
  167.                 form[f].ob_state = is;
  168.                 v_hide_c(V_handle);
  169.                 draw_object_tree(form, f, MAX_DEPTH);
  170.                 v_show_c(V_handle, 1);
  171.             }
  172.  
  173.  
  174.             if (wt->handler)
  175.             {
  176.                 ODC_PARM parm;
  177.                 parm.tree=form;
  178.                 parm.object=f;
  179.                 (*(wt->handler))(&parm);
  180.                 form[f].ob_state=os;
  181.                 draw_object_tree(form, f, MAX_DEPTH);
  182.             }else{
  183.                 clients[wt->owner].waiting_pb->intout[0] = f;
  184.                 Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long), &retv);    /* Write success to clients reply pipe to unblock the process */
  185.                 if (!(wind->created_by_FMD_START))    /* If FMD_START didn't create this window, destroy it now */
  186.                 {                                    /* - if it did, then we expect the app to call FMD_FINISH to delete the window */
  187.                     XA_WINDOW *wl=wind->next;
  188.                     
  189.                     r.g_x=wind->x;    r.g_y=wind->y;
  190.                     r.g_w=wind->w;    r.g_h=wind->h;
  191.  
  192.                     wind->is_open=FALSE;
  193.                     send_wind_to_bottom(wind);
  194.                     clients[wt->owner].zen = NULL;
  195.                     delete_window(wind);
  196.                     v_hide_c(V_handle);
  197.                     display_windows_below(&r,wl);
  198.                     v_show_c(V_handle, 1);
  199.                 }
  200.             }
  201.  
  202. /*
  203.  * How should an EXIT but not SELECTABLE be handled?
  204.  */
  205.         } else if (form[f].ob_flags & SELECTABLE) {    /* Selectable object? */
  206.  
  207. /*
  208.  * Should this perhaps be done in watch_object?
  209.  */
  210.             form[f].ob_state = is;
  211.             CLIP(form, f, x, y, w, h);
  212.             v_hide_c(V_handle);
  213.             draw_object_tree(form, f, MAX_DEPTH);
  214.             v_show_c(V_handle, 1);
  215.     
  216.             if (watch_object(form, f, is, os))
  217.             {
  218. #ifdef CLIP
  219.                 set_clip(x, y, w, h);
  220. #endif
  221.     
  222.                 if (form[f].ob_flags & RBUTTON)    /* Was click on a radio button? */
  223.                 {
  224.                     Radio_b(form, f);
  225.                 }
  226.                     
  227.                 if (form[f].ob_flags & EXIT)        /* Exit button? */
  228.                 {
  229.                     if (wt->handler)
  230.                     {
  231.                         ODC_PARM parm;
  232.                         parm.tree=form;
  233.                         parm.object=f;
  234.                         (*(wt->handler))(&parm);
  235.                         form[f].ob_state=os;
  236.                         draw_object_tree(form, f, MAX_DEPTH);
  237.                     }else{
  238.                 
  239.                         clients[wt->owner].waiting_pb->intout[0] = f;
  240.                         Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long), &retv);    /* Write success to clients reply pipe to unblock the process */
  241.         
  242.                         if (!(wind->created_by_FMD_START))    /* If FMD_START didn't create this window, destroy it now */
  243.                         {                                    /* - if it did, then we expect the app to call FMD_FINISH to delete the window */
  244.                             XA_WINDOW *wl=wind->next;
  245.                             
  246.                             r.g_x=wind->x;    r.g_y=wind->y;
  247.                             r.g_w=wind->w;    r.g_h=wind->h;
  248.  
  249.                             wind->is_open=FALSE;
  250.                             send_wind_to_bottom(wind);
  251.                             clients[wt->owner].zen = NULL;
  252.                             delete_window(wind);
  253.                             v_hide_c(V_handle);
  254.                             display_windows_below(&r,wl);
  255.                             v_show_c(V_handle, 1);
  256.                             
  257.                         }
  258.                     
  259.                     }
  260.                 }
  261.             
  262.             }
  263.         }
  264.     }
  265.     
  266. #ifdef CLIP
  267.     clear_clip();
  268. #endif
  269.     
  270.     return FALSE;
  271. }
  272.  
  273. /*
  274.     Form_do() double click handler
  275. */
  276. short dclick_object_widget(XA_WINDOW *wind, XA_WIDGET *widg)
  277. {
  278.     short x, y, w, h, f, is, os;
  279.     unsigned long retv = XA_OK;
  280.     XA_WIDGET_TREE *wt = (XA_WIDGET_TREE*)widg->stuff;
  281.     OBJECT *form;
  282.  
  283. #if 0
  284.     if (window_list != wind)    /* You can only work alerts when they are on top */
  285.         return FALSE;
  286. #endif
  287.     if (window_list != wind) {
  288.         v_hide_c(V_handle);
  289.         pull_wind_to_top(wind);
  290.         display_window(wind);
  291.         v_show_c(V_handle, 1);
  292.         return FALSE;
  293.     }
  294.    
  295.     form = wt->tree;
  296.  
  297.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  298.  
  299.     f = find_object(form, 0, 10, x + widg->click_x, y + widg->click_y);
  300.  
  301.     /* find_object can't report click on a HIDETREE object. */
  302. #if 0
  303.     if (((form[f].ob_flags & HIDETREE)        /* Was click on a valid selectable object? */
  304. #endif
  305.     if ((form[f].ob_state & DISABLED)    /* Was click on a valid selectable object? */
  306.         ||(!(form[f].ob_flags & (EDITABLE | SELECTABLE | EXIT | TOUCHEXIT))))
  307.     {    
  308.         return FALSE;
  309.     }
  310.  
  311.     switch(form[f].ob_type)
  312.     {
  313.         case G_SLIST:
  314.             dclick_scroll_list(form,f,x+widg->click_x,y+widg->click_y);
  315.             break;
  316.     }
  317.     
  318.     return FALSE;
  319. }
  320.  
  321. /*
  322.     Form Keyboard Handler
  323. */
  324. short handle_form_key(XA_WINDOW *wind, unsigned short keycode)
  325. {
  326.     XA_WIDGET *widg = (wind->widgets) + XAW_TOOLBAR;
  327.     XA_WIDGET_TREE *wt;
  328.     OBJECT *form;
  329.     TEDINFO *ed_txt;
  330.     GRECT r;
  331.     unsigned long retv = XA_OK;
  332.     char *txt;
  333.     short cursor_pos, o, ed_obj, x, y, w, h, last_ob;
  334.     int key, tmask, n, update = 0;
  335.     
  336.     DIAGS(("handle_form_key()\n"));
  337.     
  338.     wt = (XA_WIDGET_TREE*)widg->stuff;
  339.     form = wt->tree;
  340.     ed_obj = wt->edit_obj;
  341.     ed_txt = (TEDINFO*)form[ed_obj].ob_spec;
  342.     txt = ed_txt->te_ptext;
  343.     cursor_pos = ed_txt->te_tmplen;
  344.  
  345.     DIAGS(("got keypress in form\n"));
  346.     
  347.     switch(keycode)
  348.     {
  349.     case 0x011b:        /* ESCAPE clears the field */
  350.         txt[0] = '\0';
  351.         ed_txt->te_tmplen = wt->edit_pos = 0;
  352.         update = 1;
  353.         break;
  354.  
  355.     case 0x537f:        /* DEL deletes character after cursor */
  356.         if (txt[cursor_pos])
  357.         {
  358.             for(x = cursor_pos; x < ed_txt->te_txtlen - 1; x++)
  359.                 txt[x] = txt[x + 1];
  360.  
  361.             update = 1;
  362.         }
  363.         break;
  364.         
  365.     case 0x0e08:        /* BACKSPACE deletes character before cursor (if any) */
  366.         if (cursor_pos)
  367.         {
  368.             for(x = cursor_pos; x < ed_txt->te_txtlen; x++)
  369.                 txt[x - 1] = txt[x];
  370.                 
  371.             wt->edit_pos--;
  372.             ed_txt->te_tmplen = wt->edit_pos;
  373.  
  374.             update = 1;
  375.         }
  376.         break;
  377.             
  378.     case 0x0f09:        /* TAB moves to next field */
  379.     case 0x5000:        /* DOWN ARROW also moves to next field */
  380.         if (form[ed_obj].ob_flags & LASTOB)    /* Loop round */
  381.             o = 0;
  382.         else
  383.             o = ed_obj;
  384.                 
  385.         for(o++; !(form[o].ob_flags & EDITABLE); o++)        /* search for next editable object */
  386.         {
  387.             if (form[o].ob_flags & LASTOB)    /* Loop round */
  388.                 o = 0;
  389.         }
  390.  
  391.         break;
  392.  
  393.     case 0x5032:        /* SHIFT+DOWN ARROW moves to last field */
  394.         for(last_ob = 0; !(form[last_ob].ob_flags & LASTOB) ; last_ob++); /*find last object*/
  395.         o = last_ob;
  396.         for(; !(form[o].ob_flags & EDITABLE); o--) ;        /* search for last editable object */
  397.         break;
  398.         
  399.     case 0x4800:    /* UP ARROW moves to previous field */
  400.         for(last_ob = 0; !(form[last_ob].ob_flags & LASTOB) ; last_ob++); /*find last object*/
  401.         
  402.         if (ed_obj == 1)    /* Loop round ? */
  403.             o = last_ob + 1;
  404.         else
  405.             o = ed_obj;
  406.                 
  407.         for(o--; !(form[o].ob_flags & EDITABLE); o--)        /* search for previous editable object */
  408.         {
  409.             if (o == 1)    /* Loop round */
  410.                 o = last_ob + 1;
  411.         }
  412.             
  413.         break;
  414.  
  415.     case 0x4838:        /* SHIFT+UP ARROW moves to first field */
  416.         o = 0;
  417.         for(o++; !(form[o].ob_flags & EDITABLE); o++) ;    /* search for first editable object */
  418.         break;
  419.             
  420.     case 0x4d00:    /* RIGHT ARROW moves cursor right */
  421.         if ((txt[cursor_pos]) && (cursor_pos < ed_txt->te_txtlen - 1))
  422.         {
  423.             wt->edit_pos++;
  424.             ed_txt->te_tmplen = wt->edit_pos;
  425.             update = 1;
  426.         }
  427.         break;
  428.  
  429.     case 0x4d36:    /* SHIFT+RIGHT ARROW move cursor to far right of current text */
  430.         for(x = 0; txt[x]; x++) ;
  431.             
  432.         if (x != cursor_pos)
  433.         {
  434.             wt->edit_pos = x;
  435.             ed_txt->te_tmplen = wt->edit_pos;
  436.             update = 1;
  437.         }
  438.         break;
  439.             
  440.     case 0x4b00:    /* LEFT ARROW moves cursor left */
  441.         if (cursor_pos)
  442.         {
  443.             wt->edit_pos--;
  444.             ed_txt->te_tmplen = wt->edit_pos;
  445.             update = 1;
  446.         }
  447.         break;
  448.             
  449.     case 0x4b34:    /* SHIFT+LEFT ARROW move cursor to start of field */
  450.     case 0x4700:    /* CLR/HOME also moves to far left */
  451.         if (cursor_pos)
  452.         {
  453.             wt->edit_pos = ed_txt->te_tmplen = 0;
  454.             update = 1;
  455.         }
  456.         break;
  457.  
  458.     case 0x1c0d:    /* Return - select default (if any) */
  459.         o = 0;
  460.         do{
  461.             if (form[o].ob_flags & DEFAULT)
  462.             {
  463.                 if (wt->handler)
  464.                 {
  465.                     ODC_PARM parm;
  466.                     parm.tree=form;
  467.                     parm.object=o;
  468.                     (*(wt->handler))(&parm);
  469.                 }else{
  470.                     clients[wt->owner].waiting_pb->intout[0] = o;
  471.                     Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long), &retv);    /* Write success to clients reply pipe to unblock the process */
  472.                     if (!(wind->created_by_FMD_START))    /* If FMD_START didn't create this window, destroy it now */
  473.                     {                                    /* - if it did, then we expect the app to call FMD_FINISH to delete the window */
  474.                         XA_WINDOW *wl=wind->next;
  475.                         
  476.                         r.g_x=wind->x;    r.g_y=wind->y;
  477.                         r.g_w=wind->w;    r.g_h=wind->h;
  478.  
  479.                         wind->is_open=FALSE;
  480.                         send_wind_to_bottom(wind);
  481.                         clients[wt->owner].zen = NULL;
  482.                         delete_window(wind);
  483.                         v_hide_c(V_handle);
  484.                         display_windows_below(&r,wl);
  485.                         v_show_c(V_handle, 1);
  486.  
  487.                     }
  488.                 }
  489.                 return TRUE;
  490.             }
  491.             o++;
  492.         } while(!(form[o].ob_flags & LASTOB));
  493.         break;
  494.         
  495.     default:        /* Just a plain key - insert character */
  496.         if (cursor_pos == ed_txt->te_txtlen - 1) {
  497.             cursor_pos--;
  498.             wt->edit_pos--;        /* Increased below */
  499.         }
  500.  
  501.         key = keycode & 0xff;
  502.         tmask=character_type[key];
  503.  
  504.         n = strlen(ed_txt->te_pvalid) - 1;
  505.         if (cursor_pos < n)
  506.             n = cursor_pos;
  507.  
  508.         switch(ed_txt->te_pvalid[n]) {
  509.         case '9':
  510.             tmask &= CGd;
  511.             break;
  512.         case 'a':
  513.             tmask &= CGa|CGs;
  514.             break;
  515.         case 'n':
  516.             tmask &= CGa|CGd|CGs;
  517.             break;
  518.         case 'p':
  519.             tmask &= CGa|CGd|CGp|CGxp;
  520.             /*key = toupper((char)key);*/
  521.             break;
  522.         case 'A':
  523.             tmask &= CGa|CGs;
  524.             key = toupper((char)key);
  525.             break;
  526.         case 'N':
  527.             tmask &= CGa|CGd|CGs;
  528.             key = toupper((char)key);
  529.             break;
  530.         case 'F':
  531.             tmask &= CGa|CGd|CGp|CGxp|CGw;
  532.             /*key = toupper((char)key);*/
  533.             break;
  534.         case 'f':
  535.             tmask &= CGa|CGd|CGp|CGxp|CGw;
  536.             /*key = toupper((char)key);*/
  537.             break;
  538.         case 'P':
  539.             tmask &= CGa|CGd|CGp|CGxp|CGw;
  540.             /*key = toupper((char)key);*/
  541.             break;
  542.         case 'X':
  543.             tmask = 1;
  544.             break;
  545.         case 'x':
  546.             tmask = 1;
  547.             key = toupper((char)key);
  548.             break;
  549.         default:
  550.             tmask = 0;
  551.             break;            
  552.         }
  553.             
  554.         if (!tmask) {
  555.             for(n = x = 0; ed_txt->te_ptmplt[n]; n++) {
  556.                    if (ed_txt->te_ptmplt[n] == '_')
  557.                     x++;
  558.                 else if ((ed_txt->te_ptmplt[n] == key)
  559.                     && (x >= cursor_pos))
  560.                     break;
  561.             }
  562.             if (key && (ed_txt->te_ptmplt[n] == key)) {
  563.                 for(n = cursor_pos; n < x; n++)
  564.                     txt[n] = ' ';
  565.                 txt[x] = '\0';
  566.                 wt->edit_pos = x;
  567.                 ed_txt->te_tmplen = wt->edit_pos;
  568.             } else {
  569.                 wt->edit_pos = ed_txt->te_tmplen;
  570.                 return(TRUE);
  571.             }
  572.         } else {
  573.             txt[ed_txt->te_txtlen - 2] = '\0';    /* Needed! */
  574.             for(x = ed_txt->te_txtlen - 1; x > cursor_pos; x--)
  575.                 txt[x] = txt[x - 1];
  576.  
  577.             txt[cursor_pos] = (char)key;
  578.  
  579.             wt->edit_pos++;
  580.             ed_txt->te_tmplen = wt->edit_pos;
  581.         }
  582.             
  583.         update = 1;
  584.         break;
  585.     }
  586.     if (update) {        /* Moved from a number of places above. */
  587.         CLIP(form, ed_obj, x, y, w, h);
  588.         v_hide_c(V_handle);
  589.         draw_object_tree(form, ed_obj, MAX_DEPTH);
  590.         v_show_c(V_handle, 1);
  591.     }
  592.     switch(keycode) {    /* Moved from four places above. */
  593.     case 0x0f09:        /* All the common updating is */
  594.     case 0x5000:        /* done here now. */
  595.     case 0x5032:
  596.     case 0x4800:
  597.     case 0x4838:
  598.         if (o != ed_obj)    /* If edit field has changed, update the display */
  599.         {
  600.             form[o].ob_state |= IS_EDIT;
  601.             form[ed_obj].ob_state &= ~IS_EDIT;
  602.             
  603.             CLIP(form, ed_obj, x, y, w, h);
  604.             v_hide_c(V_handle);
  605.             draw_object_tree(form, ed_obj, MAX_DEPTH);
  606.  
  607.             wt->edit_obj = o;
  608.             wt->edit_pos = ((TEDINFO*)form[o].ob_spec)->te_tmplen = strlen(((TEDINFO*)form[o].ob_spec)->te_ptext);
  609.         
  610.             CLIP(form, o, x, y, w, h);
  611.             draw_object_tree(form, o, MAX_DEPTH);
  612.             v_show_c(V_handle, 1);
  613.         }
  614.         break;
  615.     }
  616.             
  617.     return TRUE;
  618. }
  619.